define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'upload'], function ($, undefined, Backend, Table, Form, Upload) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'god/student/index',
                    add_url: 'god/student/add',
                    edit_url: 'god/student/edit',
                    del_url: 'god/student/del',
                }
            });

            var table = $("#table");

            //在表格内容渲染完成后回调的事件

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'state', checkbox: true,},
                        {field: 'id', title: 'ID'},
                        {field: 'name', title: '姓名'},
                        {field: 'id_type_text', title: '证件类型'},
                        {field: 'id_code', title: '证件号码'},
                        {field: 'sex', title: '性别'},
                        {field: 'birthday', title: '生日'},
                        {field: 'mobile', title: '手机'},
                        {field: 'nation', title: '民族'},
                        {field: 'political', title: '政治面貌'},
                        {field: 'hours_type', title: '户籍类型'},
                        {field: 'hours_address', title: '户籍所在地'},
                        {
                            field: 'delivery_address', title: '地址', formatter: function (value, row, index) {
                                return value + row.delivery_area;
                            }
                        },
                        {field: 'occupation_type', title: '职业类型'},
                        {field: 'occupation', title: '职位'},
                        {field: 'entry', title: '入职时间'},
                        {field: 'company_address', title: '公司所在地'},
                        {field: 'company_tel', title: '公司联系电话'},
                        {field: 'company_postcode', title: '邮箱'},
                        {field: 'emergency_tel', title: '紧急电话'},
                        {
                            field: 'status',
                            title: __("Status"),
                            searchList: {"normal": __('Normal'), "hidden": __('Hidden')},
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'create_time',
                            title: '创建时间',
                            formatter: Table.api.formatter.datetime,
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                return Table.api.formatter.operate.call(this, value, row, index);
                            }
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);


        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        }
    };
    // 给上传按钮添加上传成功事件
    $("button#faupload-picture").data("upload-success", function (data) {
        let url = Backend.api.cdnurl(data.url);
        console.log(url);
        $(".stu-img").prop("src", data.url);
        $('input#picture').val(url);
        Toastr.success("上传成功！");
    });

    return Controller;
});
